﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.InteropServices;
using RestAndPlay.Core.Model;
using RestAndPlay.Core.Repository;
using RestAndPlay.Indexer.Indexer;
using System.Diagnostics;
using System.Threading.Tasks;

namespace RestAndPlay.Indexer
{

    [ServiceContract]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class IndexerService
    {

        [WebGet(UriTemplate = "add?username={username}&directory={directory}",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json)]
        void AddSource(String username, String directory)
        {
            Trace.TraceInformation(string.Format("AddSource(username = {0}, directory = {1})", username, directory));
            try
            {

                new Task(() => DirectoryIndexer.Index(directory));

                return;

            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }
        }


    }

}
